package com.noble.meether.chat.ui.agora.act.comment;

import android.graphics.Bitmap;
import android.graphics.drawable.BitmapDrawable;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;

import com.noble.meether.R;
import com.noble.glamour.bean.center.user.detail.UserDetail;
import com.noble.glamour.module.logic.config.UrlParam;
import com.noble.glamour.module.logic.request.HttpResponse;
import com.noble.glamour.module.logic.request.RequestComplete;
import com.noble.library.base.BaseAppCompatActivity;
import com.noble.library.image.ImageLoader;
import com.noble.library.utils.BitmapUtil;
import com.noble.library.utils.UIUtil;
import com.noble.meether.chat.ui.agora.util.RtcJointChannel;

/**
 * 视频结束后评价，结算
 */
public class RtcCommentActivity extends BaseAppCompatActivity implements View.OnClickListener, RequestComplete {
    private RtcCommentFootPanel footPanel;
    private ImageView imgHead, imgBg;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        isCanBack(false);
        super.onCreate(savedInstanceState);
        setContentView(R.layout.f1_chat_video_comment);
        initView();
    }

    private void initView() {
        imgBg = findViewById(R.id.iv_bg);
        Bitmap bitmap = BitmapUtil.getDecodeBitmap(this, R.drawable.sp_bk, 320, 480);
        UIUtil.setBackground(imgBg, new BitmapDrawable(null, bitmap));

        imgHead = findViewById(R.id.img_header);
        ImageLoader.loadCircleAvatar(this, R.drawable.default_head, imgHead);
        findViewById(R.id.iv_close).setOnClickListener(this);
        findViewById(R.id.btn_submit).setOnClickListener(this);
        LinearLayout container = findViewById(R.id.container);
        footPanel = new RtcCommentFootPanel(this);
        container.addView(footPanel.getContentView());
        RtcJointChannel.getInstance().reqUserInfo(this);
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.btn_submit:
                footPanel.onSubmit();
                break;

            case R.id.iv_close:
                finish();
                break;
        }
    }

    @Override
    public void onRequestComplete(HttpResponse response) {
        if (response.getUrlParam() == UrlParam.reqMyInfo) {
            if (!response.isOk()) return;
            UserDetail userDetail = (UserDetail) response.getBaseData();
            ImageLoader.loadBlur(this, userDetail.getAvatar(), imgBg, 8, R.drawable.sp_bk);
            ImageLoader.loadCircleAvatar(this, userDetail.getAvatar(), imgHead);
            return;
        }
    }
}
